﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PropertyDataContext.Model;
using PropertyDataContext.Repositery;

namespace PropertyDataContext.UnitOfWork
{
    public class UOWEntities : IDisposable
    {
        PropertyRepositery<Agent> _agentRepositery;

        PropertyRepositery<AdminAgent> _adminAgentRepositery;

        PropertyRepositery<Admin> _adminRepositery;

        PropertyDatabaseEntities context = new PropertyDatabaseEntities();

        public PropertyRepositery<Agent> agentRepositery
        {
            get
            {
                if (this.agentRepositery == null)
                    this._agentRepositery = new PropertyRepositery<Agent>(context);
                return agentRepositery;
            }
        }

        public PropertyRepositery<AdminAgent> adminAgentRepositery
        {
            get
            {
                if (this.adminAgentRepositery == null)
                    this._adminAgentRepositery = new PropertyRepositery<AdminAgent>(context);
                return adminAgentRepositery;
            }
        }

        public PropertyRepositery<Admin> adminRepositery
        {
            get
            {
                if (this.adminRepositery == null)
                    this._adminRepositery = new PropertyRepositery<Admin>(context);
                return adminRepositery;
            }
        }

        public void Save()
        {
            context.SaveChanges();
        }

        private bool disposed = false;

        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    context.Dispose();
                }
            }
            this.disposed = true;
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
    }
}
